﻿using DingTalk.Core.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DingTalk.Corp.Auth.Models
{
    /// <summary>
    /// {
    ///     "clientSecret":"",
    ///     "clientId":"",
    ///     "code":"836bdeb378a83c4f993fc2e4ee5efa5b",
    ///     "grantType":"authorization_code"
    /// }
    /// </summary>
    public class UserTokenRequest
    {
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("clientId")]
        public string AppKey { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("clientSecret")]
        public string AppSecret { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("code")]
        public string AuthCode { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("refreshToken")]
        public string RefreshToken { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("grantType")]
        public string GrantType { get; set; }
    }
    /// <summary>
    /// {
    ///     "expireIn":7200,
	///     "accessToken":"cfac291e4d5b3d948de6e439500d9d52",
	///     "refreshToken":"6f43e726ed5936869e772b83eea979cb"
    /// }
    /// </summary>
    public class UserTokenResponse : StandardResponse
    {
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("accessToken")]
        public string AccessToken { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("refreshToken")]
        public string RefreshToken { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("expireIn")]
        public int ExpiresIn { get; set; }
        [JsonIgnore]
        internal DateTime ExpiresTime { get; set; }
        [JsonIgnore]
        internal DateTime RefreshTime
        {
            get
            {
                return ExpiresTime.AddHours(-1);
            }
        }
    }
}
